<?php
class Hotspot{

	/* This class will interface directly with the MySQL database, and provide
	 * methods for manipulating hotspots.
	 */

	private $ID,
		$UID,
		$coordinates, //array of x,y pairs
		$coordinatesCount,
		$designation; //integer ID

	public function __construct($HotspotID,$new=false,$args=false){
		//get this hotspot from the Database, if new flag is set,
		//ignore ID and make new using args
		if($new==true)
		{
			$this->UID = $args['uid'];
			$this->coordinates = $args['coordinates'];
			$this->coordinatesCounts = $args['coordinatesCount'];
			$this->designation = $args['designation'];			
			$sql = "INSERT INTO users (uid, coordinates, coordinatescount, designation) VALUES('" . $this->uid . "', '"  . $this->coordinates . "', '" . $this->coordinatesCount . "', '" . $this->designation . "')";
			mysql_query($sql);
		}
		else
		{
			$sql = "SELECT * FROM hotspots WHERE id=" . $HotspotID;
        	$result = mysql_query($sql);
        	$row = mysql_fetch_array($result, MYSQL_ASSOC));
			$this->ID = $HotspotID; 
			$this->UID = $row['uid'];
			$this->coordinates = $row['coordinates'];
			$this->coordinatesCounts = $row['coordinatescount'];
			$this->designation = $row['designation'];			
		}
		
		
	}
	public function getCoordinates(){
		return $this->coordinates;
	}
	public function getCoordCount(){
		return $this->coordinatesCount;
	}
	public function getDesignation(){
		return $this->designation;
	}
	public function setCoordinates($newCoords){
		$this->coordinates = $newCoords;
		$sql = "INSERT INTO users (coordinates) VALUES('" . $this->coordinates . "')";
		mysql_query($sql);
	}
	public function setDesignation($newDesingation){
		$this->designation = $newDesignation;
		$sql = "INSERT INTO users (designation) VALUES('" . $this->designation . "')";
		mysql_query($sql);		
	}
}
?>